package lib.bone.access.module.userpost.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * @Author : kindear
 * @Date : 2021-12-13
 * 用户-岗位信息 映射表
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "nepu_user_post")
@EntityListeners(AuditingEntityListener.class)
@ApiModel(value = "用户岗位映射")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class NepuUserPost {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "记录ID",name = "id")
    String id;

    /**
     * 对应的用户ID
     */
    @ApiModelProperty(value = "用户ID",notes = "映射system-user 信息,不存在则新建")
    @Column(name = "user_id")
    Long userId;

    /**
     * 对应的岗位ID
     */

    @ApiModelProperty(value = "岗位ID",notes = "映射nepu-post 信息,不存在则新建")
    @Column(name = "post_id")
    String postId;

    /**
     * 人才引进标识
     */

    @ApiModelProperty(value = "是否为引进",notes = "1 为 引进 0 为非引进")
    @Column(name = "is_special")
    Integer isSpecial;

    /**
     * 一对一关系
     * 关联合同信息
     */
//    @JsonIgnoreProperties(value = {"nepuUserPost"})
////    @OneToOne(cascade = {CascadeType.PERSIST,CascadeType.REMOVE})
////    @JoinColumn(name="contract_id",referencedColumnName = "id")
//    NepuContract nepuContract;
    //年度考核基本合格的，不发岗位绩优奖励、年终一次性奖金；年度考核不合格、不定等级的，不发放岗位绩优奖励和年终一次性奖金，教师不发放岗位津贴，教学工作量按教分发放，管理人员按岗位津贴的50%发放。
    @ApiModelProperty(value = "年度考核",notes = "合格，基本合格，不合格")
    @Column(name = "annual_assessment")
    String annualAssessment;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NepuUserPost that = (NepuUserPost) o;
        return id != null && Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
